package com.example.chat.mapper;

import com.example.chat.entity.FileUpload;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/8/6 20:34
 **/
@Mapper
public interface FileUploadMapper {

    @Insert("""
insert into file_upload (file_id, original_name, storage_path, file_size, file_type, uploader_id, upload_time,
status, bucket_name, client_ip) values (#{fileId}, #{originalName}, #{storagePath}, #{fileSize}, #{fileType},
#{uploaderId}, #{uploadTime}, #{status}, #{bucketName}, #{clientIp})
""")
    void insertFileUpload(FileUpload fileUpload);

    @Select("""
<script>
    SELECT * FROM file_upload WHERE 
    1 = 1
    <if test='fileId != null and fileId != ""'> AND file_id = #{fileId} </if>
    <if test='originalName != null and originalName != ""'> AND original_name = #{originalName} </if>
</script>
""")
    FileUpload queryFileUpload(@Param("fileId") String fileId, @Param("originalName") String originalName);
}
